import random

import requests
import logging
import config


class RoleApi:

    # 获取角色列表
    @classmethod
    def get_rolelist(cls, token, roleName, dataScope, menuCheckStrictly, status, isDefault):
        url = config.monitor_domain + f"/system/role/list?roleName={roleName}&dataScope={dataScope}&menuCheckStrictly={menuCheckStrictly}&status={status}&isDefault={isDefault}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"get_rolelist url:{url}")
        logging.info(f"get_rolelist resp: {resp.text}")
        return resp

    # 角色列表导出
    @classmethod
    def role_export(cls, token, roleName, dataScope, menuCheckStrictly, status, isDefault):
        url = config.monitor_domain + f"/system/role/export?roleName={roleName}&dataScope={dataScope}&menuCheckStrictly={menuCheckStrictly}&status={status}&isDefault={isDefault}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"role_export url:{url}")
        logging.info(f"role_export resp: {resp.text}")
        return resp

        pass

    # 根据角色编号获取详细信息
    @classmethod
    def get_roleDetailed(cls, token, roleId):
        url = config.monitor_domain + f"/system/role/{roleId}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"get_roleDetailed url:{url}")
        logging.info(f"get_roleDetailed resp: {resp.text}")
        return resp
    #加载对应角色菜单列表树
    @classmethod
    def get_roleMenuTreeselect(cls, token, roleId):
        url = config.monitor_domain + f"/system/menu/roleMenuTreeselect/{roleId}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"get_roleMenuTreeselect url:{url}")
        logging.info(f"get_roleMenuTreeselect resp: {resp.text}")
        return resp

    pass
